package com.myblog.controller;

import com.myblog.Utils.BeanCopyUtils;
import com.myblog.domain.GlobalResponse;
import com.myblog.domain.Vo.RoleVo;
import com.myblog.domain.dto.AddRoleDto;
import com.myblog.domain.dto.RoleDto;
import com.myblog.domain.dto.UpdateRoleDto;
import com.myblog.domain.entity.Role;
import com.myblog.services.RoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/system/role")
public class RoleController {
    @Resource
    RoleService roleService;
    @PostMapping()
    public GlobalResponse addRole(@RequestBody AddRoleDto roleDto){
        return roleService.saveRole(roleDto);
    }
    @GetMapping("/list")
    public GlobalResponse getRoleList(Integer pageNum,Integer pageSize,String roleName,String status){
        return roleService.getList(pageNum,pageSize,roleName,status);
    }

    @PutMapping("/changeStatus")
    public GlobalResponse changeStatus(@RequestBody RoleDto roleDto){
        return roleService.changeStatus(roleDto);
    }

    @GetMapping("/{id}")
    public GlobalResponse getRole(@PathVariable Long id){
        Role role = roleService.getById(id);
        RoleVo roleVo = BeanCopyUtils.copyBean(role, RoleVo.class);
        return GlobalResponse.ok(roleVo);
    }
    @PutMapping()
    public GlobalResponse updateRole(@RequestBody UpdateRoleDto updateRoleDto){
        return roleService.updateRole(updateRoleDto);
    }

    @DeleteMapping("/{id}")
    public GlobalResponse deleteRole(@PathVariable Long id){
        return  roleService.deleteRole(id);
    }

    @GetMapping("/getAllRole")
    public GlobalResponse getAllRole(){
        return roleService.getAllRole();
    }

}
